/**
***	CHAMBONNET Kevin
**/


#include <iostream>
#include <string>

#include "/usr/include/netdb.h"

// Pour utiliser : inet_ntoa, ...
#include "/usr/include/netinet/in.h"
#include "/usr/include/arpa/inet.h"
#include "/usr/include/sys/socket.h"

using namespace std;

int main(int argc, char** argv)
{
	if(argc > 1)
	{
		struct hostent* host = gethostbyname(argv[1]);
		
		std::cout << "Host Name : " <<  host->h_name << std::endl;
		std::cout << "Host addrtype : " <<  host->h_addrtype << std::endl;
		
		std::cout << "Host alias : " << std::endl;
		
		int k = 0;
		while(host->h_aliases[k] != NULL)
		{
			std::cout << host->h_aliases[k] << std::endl;
			k++;
		}
		
		
		
		std::cout << "Address : [" << host->h_length << "] " << std::endl;
		k = 0;
		while(host->h_addr_list[k] != NULL)
		{
			
			/// Methode de base :
			
// 			for(int i(0); i<host->h_length; i++)
// 			{
// 				std::cout << (int(u_char(host->h_addr_list[k][i])));
// 				
// 				if(i != host->h_length-1)
// 				{
// 					std::cout << ":";
// 				}
// 			}
// 			
// 			
			
			/// Avec inet_ntoa :
			
			std::cout << inet_ntoa( *(struct in_addr*)(host->h_addr_list[k]) );
			
			k++;
			
			std::cout << std::endl;
		}
		
		std::cout << std::endl;
	}
	else
	{
		std::cout << "Pas d'argument" << std::endl;
	}

	return 0;
} 
